package com.example.shushiyunsst.fragment.main.mine.child

import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.library_common.base.BaseDataBindingFragment
import com.example.library_common.base.BaseFragmentEx
import com.example.library_common.utils.PixUtils
import com.example.shushiyunsst.R
import com.example.shushiyunsst.databinding.ShareFragmentBinding
import com.example.shushiyunsst.fragment.main.home.child.miner22.Miner22ShareFragment
import com.example.shushiyunsst.util.EncodingHandler
import com.example.shushiyunsst.util.SHARE
import com.example.shushiyunsst.util.clipboard
import com.example.wallet.db.UserInfoManager

@Route(path = SHARE)
class ShareFragment : BaseDataBindingFragment<ShareFragmentBinding>(), View.OnClickListener {

    companion object {
        fun newInstance(): ShareFragment {
            val args = Bundle()
            val fragment = ShareFragment()
            fragment.arguments = args
            return fragment
        }
    }

//    private var path = ""
//
//    private var createQRCode: Bitmap? = null

    private val  ls= listOf<BaseFragmentEx>(
        SharePostFragment.newInstance(),
        Miner22ShareFragment.newInstance()
    )

    override fun layoutId(): Int {
        return R.layout.share_fragment
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val mToolbar: Toolbar = view.findViewById(R.id.mToolbar)
        mToolbar.title = "分享推广"
        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }

        viewBinder.mViewPager.adapter=object :
            FragmentPagerAdapter(childFragmentManager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT){
            override fun getCount(): Int {
                return ls.size
            }

            override fun getItem(position: Int): Fragment {
               return ls[position]
            }

            override fun getPageTitle(position: Int): CharSequence? {
               val shareLabel=getItem(position) as ShareLabel
                return shareLabel.labelInfo()
            }
        }
        viewBinder?.mTabLayout?.setupWithViewPager(viewBinder.mViewPager)
//
//        viewBinder.onViewClick = this
//        val userInfoManager = UserInfoManager.userInfoManager
//        val userInfoWrapper = userInfoManager.getUserInfoWrapper()
//        val userInfo = userInfoWrapper?.userInfo
//        viewBinder.tvMCoding.text = "您的邀请码：${userInfo?.invitationCode}"
//
//
//        try {
////            val str="http://token.regyun.com/download/sstwallet.apk"
//            val code = userInfoManager.getUserInfoWrapper()?.userInfo?.invitationCode
//            path =
//                "http://app.regyun.com/index.html?code=${code}"
//            createQRCode =
//                EncodingHandler.createQRCode(path, PixUtils.dp2px(170))
//
//            viewBinder.mCoding.setImageBitmap(createQRCode)
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }
    }

    override fun onClick(v: View?) {
//        when (v?.id) {
//            R.id.bottom -> {
//
//            }
//            R.id.mCopyTv -> {
////                val userInfoManager = UserInfoManager.userInfoManager
////                val userInfoWrapper = userInfoManager.getUserInfoWrapper()
////                val userInfo = userInfoWrapper?.userInfo
//                clipboard("path",path)
//            }
//        }
    }

    override fun onDestroy() {
        super.onDestroy()
//        if (createQRCode?.isRecycled == false) {
//            createQRCode?.recycle()
//        }
    }

}